import { ApiProperty, getSchemaPath } from "@nestjs/swagger";
import { CrudValidationGroups } from "@nestjsx/crud";
import { IsString } from "class-validator";
import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
import { Assets } from "./assets.entity";
import { BaseEntity } from "./base.entity";
import { Funds } from "./funds.entity";
import { Migrate } from "./migrate.entity";
import { OrgAction } from "./org-action.entity";
import { PartyMember } from "./party-member.entity";
import { ProjectConstruction } from "./project-construction.entity";
import { Resources } from "./resources.entity";
import { SubsidyInfo } from "./subsidy-info.entity";
import { VillageAction } from "./village-action.entity";
import { VillageCadre } from "./village-cadre.entity";
import { VillageMeeting } from "./village-meeting.entity";
import { Village } from "./village.entity";
import { Villager } from "./villager.entity";

const { CREATE, UPDATE } = CrudValidationGroups;


@Entity()
export class Group extends BaseEntity {
  @ApiProperty({
    description: '组主键',
    required: false,
    type: Number
  })
  @PrimaryGeneratedColumn()
  id ?: number;

  @ApiProperty({
    example: 1,
    description: '所属村',
    required: true,
    oneOf: [
      {
        type: 'Number'
      },
      {
        $ref: getSchemaPath(() => Village)
      }
    ]
  })
  @ManyToOne(() => Village, Village => Village.group, {
    eager: true,
    cascade: true
  })
  village: Number | Village

  @ApiProperty({
    example: '组名',
    description: '组名',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
  })
  name: string
  
  @ApiProperty({
    example: 1,
    description: '村民',
    required: false,
    type: [() => Villager]
  })
  @OneToMany(() => Villager, Villager => Villager.group, { 
    eager: true
  })
  villager : Villager []

  @ApiProperty({
    example: 1,
    description: '村干部',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => VillageCadre,
    VillageCadre => VillageCadre.group,
  )
  villageCadre?: VillageCadre [];


  @ApiProperty({
    example: 1,
    description: '党员',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => PartyMember,
    PartyMember => PartyMember.group,
  )
  partyMember?: PartyMember[];


  @ApiProperty({
    example: 1,
    description: '补助信息',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => SubsidyInfo,
    SubsidyInfo => SubsidyInfo.group,
  )
  subsidyInfo?: SubsidyInfo[];

  @ApiProperty({
    example: 1,
    description: '迁移信息',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => Migrate,
    Migrate => Migrate.group,
  )
  migrate?: Migrate[];

  @ApiProperty({
    example: 1,
    description: '资源',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => Resources,
    Resources => Resources.group,
  )
  resources?: Resources[];

  @ApiProperty({
    example: 1,
    description: '资产',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => Assets,
    Assets => Assets.group,
  )
  assets?: Assets[];

  @ApiProperty({
    example: 1,
    description: '资金',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => Funds,
    Funds => Funds.group,
  )
  funds?: Funds[];

  @ApiProperty({
    example: 1,
    description: '项目建设信息',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => ProjectConstruction,
    ProjectConstruction => ProjectConstruction.group,
  )
  projectConstruction?: ProjectConstruction[];


  @ApiProperty({
    example: 1,
    description: '村会议',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => VillageMeeting,
    VillageMeeting => VillageMeeting.group,
  )
  villageMeeting?: VillageMeeting[];

  @ApiProperty({
    example: 1,
    description: '村组织活动',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => VillageAction,
    VillageAction => VillageAction.group,
  )
  villageAction?: VillageAction[];

  @ApiProperty({
    example: 1,
    description: '党组织活动',
    required: false,
    type: Number,
  })
  @OneToMany(
    () => OrgAction,
    OrgAction => OrgAction.group,
  )
  orgAction?: OrgAction[];

}